import os
import sys
import hashlib
import shutil

def md5(fname):
    hash = hashlib.md5()
    with open(fname, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash.update(chunk)
    return hash.hexdigest()

def del_local_dou(local):
    #todo delete .doc .jpeg etc.
    dic = {}
    for root,dirs,files in os.walk(local):
        print root
        if len(files) > 0:
            for tmpFile in files:
                filePath = os.path.join(root, tmpFile)
                md5Key = md5(filePath)
                fileExist = dic.get(md5Key, None)
                if fileExist:
                    print 'delete' + filePath + '\n'
                    print 'exist path:' + fileExist
                    os.remove(filePath)
                else:
                    dic[md5Key] = filePath

    return dic

def copy_new_file(localDic, destDic, destNewDir):
    for dicKey in localDic:
        fileExist = destDic.get(dicKey, None)
        if not fileExist:
            pass
        else:


def diff_path_dou(local, dest):
    localDic = del_local_dou(local)
    destDic = del_local_dou(dest)

    localNew = os.path.join(local, 'newfile')
    os.mkdir(localNew)

    destNew = os.path.join(dest, 'newfile')
    os.mkdir(destNew)
    
    copy_new_file(localDic, destDic, destNew)
    copy_new_file(destDic, local, localNew)

if __name__ == '__main__':
    argvNum = len(sys.argv)
    if argvNum == 3:
        local = sys.argv[1]
        dest = sys.argv[2]
        print local, dest
        diff_path_dou(local, dest)

    elif argvNum == 2:
        local = sys.argv[1]
        print local
        del_local_dou(local)